-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RFC: Allow Irrefutable Patterns in if-let and while-let statements #2086
RFC: Allow Irrefutable Patterns in if-let and while-let statements #2086
Conversation
@Nokel81 The title of the PR should be the RFC name (you can edit it). |
I thoroughly disagree. This is already solved right now - the code is wrong and thus an error. You're proposing a different solution which has to deal with this. If anything, this is an unresolved question: If we can't solve it by making it an error, how do we solve it? This RFC is also missing its Alternatives section even though I can think of two options off the top of my head:
|
I will add those alternatives. From what I understand |
Indeed it is not but perhaps that could be changed? In any case, you could always just add the attribute to a surrounding block. |
I would say that it should be changed since from what I understand it is unique to |
I think Would it work if there were a way to declare an irrefutable pattern refutable? |
So instead of a warning, keep it a error but still have an |
I'd be in favour of the lint option here - seems reasonable for macros to |
I likewise prefer the solution of making this an error-by-default lint that macros can turn off. For non-macro code, errors like this help Rust users (especially new users) learn and avoid using suboptimal forms that just happen to work. And macros can easily turn the lint off. |
I am definitely in favor of some way to relax this error. I've stumbled on this in macros, and existing workarounds are not great. It's worth pointing out that |
@Nokel81 In the @rust-lang/lang meeting, we were all in favor of the solution of making this an error-by-default lint. Could you please adjust the RFC to that effect, and then we'd be inclined to accept it? |
Yup, done. I hope the wording is to your liking |
@Nokel81 Thanks for the fast response! What's there looks reasonable, but it would help if the summary section had an explanation of the proposed change and reason (e.g. "This can break macros that want to accept patterns generically; this RFC proposes changing this to an error-by-default lint that can be disabled by such macros."). Also, in the detailed design section, please come up with a proposed name for the lint (e.g. |
…A proposed lint name and some code examples
How is this? |
@Nokel81 The verbiage looks great. One minor nit: lint names use underscores, not dashes, so can you |
Done |
Thanks @Nokel81 and @joshtriplett! @rfcbot fcp merge |
Team member @aturon has proposed to merge this. The next step is review by the rest of the tagged teams: No concerns currently listed. Once these reviewers reach consensus, this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
@aturon Shouldn't |
As a minor note, I don't like the lint name, because a "let pattern" (i.e. |
The reason that I went with this name is because the current error is "irrefutable if-let pattern". We could change the lint but then what about for while loops (though that may be out of the scope of this RFC) |
I have a minor nit with the RFC as written. Under the "Motivation" section the following phrase makes no sense to me:
I'm not sure what this is actually trying to say, really, but perhaps it could be reworded? |
if let $p = $val { | ||
$b | ||
} | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These two adjacent code blocks are confusing, especially since the second one starts a new thought.
I picture something more along the lines of:
Currently, one must write
(first example)
rather than the more natural syntax
(second example)
because reasons.
[summary]: #summary | ||
|
||
Currently when using an if let statement and an irrefutable pattern (read always match) is used the compiler complains with an `E0162: irrefutable if-let pattern`. | ||
The current state breaks macros who want to accept patterns generically and this RFC proposes changing this error to an error-by-default which is allowed to be disabled by such macros. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
error-by-default lint?
Changed the flow of the motivation section so as to better distinguish the code examples. Added the word 'lint' as it was missing from the summary section
The final comment period is now complete. |
This RFC has been merged! Tracking issue. Thanks @Nokel81! |
Thank you |
@Nokel81 the rendered link is now broken |
@vitiral fixed |
…matsakis Implementation of RFC 2086 - Allow Irrefutable Let patterns This is the set of changes for RFC2086. Tracking issue #44495. Rendered [here](rust-lang/rfcs#2086)
This is an RFC for allowing irrefutable patterns in if-let and while-let statements
Edit: Rendered
[updated to link to final rendered version]